﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace SHARED
{
    public class database
    {
        public void Try()
        {
            //root master element, parent is null
            //Element rootEl = new Element("Results");
            //MasterElement rootMasterElement = new MasterElement(0);
            //rootMasterElement.elements.Add(rootEl);

            ////master element -> level 1
            //Element name = new Element("Name");
            //Element Age = new Element("Age");
            //Element Phone = new Element("Phone");
            //Element customerAddr = new Element("CustomerAddr", true);
            //MasterElement customerInfo = new MasterElement(1);
            //customerInfo.AddElement(name);
            //customerInfo.AddElement(Age);
            //customerInfo.AddElement(Phone);
            //customerInfo.AddElement(customerAddr);
            //customerInfo.Parent = rootMasterElement;

            ////master element -> level 2
            //Element address = new Element("Address");
            //Element City = new Element("City");
            //Element ZipCode = new Element("ZipCode");
            //MasterElement addressDetails = new MasterElement(2);
            //addressDetails.AddElement(address);
            //addressDetails.AddElement(City);
            //addressDetails.AddElement(ZipCode);
            //addressDetails.Parent = customerInfo;

            ////set children property
            //rootMasterElement.AddChild(customerInfo);
            //customerInfo.AddChild(addressDetails);

            //MasterElementList list = new MasterElementList(rootMasterElement);
            //list.Add(customerInfo);
            //list.Add(addressDetails);



            MSSQL msSql = new MSSQL();


            Element rootEl = new Element("Results");
            MasterElement rootMasterElement = new MasterElement(0);
            rootMasterElement.elements.Add(rootEl);

            //master element -> level 1
            Element SysStem = new Element("System_ID");
            Element SystemInfo = new Element("SystemInfo", true);
            MasterElement Systems = new MasterElement(1);
            Systems.AddElement(SysStem);
            Systems.AddElement(SystemInfo);
            Systems.Parent = rootMasterElement;

            //master element -> level 2
            Element systemID = new Element("Windows_ID");
            Element AppID = new Element("App_ID");
            //Element ZipCode = new Element("ZipCode");
            MasterElement sysDetails = new MasterElement(2);
            sysDetails.AddElement(systemID);
            sysDetails.AddElement(AppID);
            sysDetails.Parent = Systems;

            MasterElementList list = new MasterElementList(rootMasterElement);
            list.Add(Systems);
            list.Add(sysDetails);

            SqlCommand com = new SqlCommand();
            com.CommandText = "Select System_ID, Windows_ID, App_ID FROM DIG_MASTER_INFO";


            //msSql.ExecuteSelectCommand(com);
            MasterElementList result = msSql.ExecuteSelectCommandObject(com, list, rootMasterElement);

            Logger log = new Logger();
            for (int i = 0; i < result.Count; i++)
            {
                log.LogMessageToFile("Master Element -- Beginning");
                for (int j = 0; j < result[i].elements.Count; j++)
                {
                    log.LogMessageToFile("parent");
                    if (result[i].Parent == null)
                    {
                        log.LogMessageToFile("parent null");
                    }
                    else
                    {
                        log.LogMessageToFile("-> tag name" + result[i].Parent.elements[0].tagName + " tag value " + result[i].Parent.elements[0].tagName);
                    }
                    log.LogMessageToFile("actual element");
                    log.LogMessageToFile("tag name " + result[i].elements[j].tagName + " tag value " + result[i].elements[j].tagValue);
                }
                log.LogMessageToFile("Master Element -- End");
            }





        }
    }
}
